package com.excesys.exsecs.eco.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.excesys.exsecs.common.core.util.R;
import com.excesys.exsecs.common.log.annotation.SysLog;
import com.excesys.exsecs.eco.entity.EcoWeatherFlow;
import com.excesys.exsecs.eco.service.EcoWeatherFlowService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.excesys.exsecs.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 天气流水表
 *
 * @author lxc
 * @date 2024-11-29 10:07:03
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/ecoWeatherFlow" )
@Tag(description = "ecoWeatherFlow" , name = "天气流水表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class EcoWeatherFlowController {

    private final EcoWeatherFlowService ecoWeatherFlowService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param ecoWeatherFlow 天气流水表
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('exsecs_ecoWeatherFlow_view')" )
    public R getEcoWeatherFlowPage(@ParameterObject Page page, @ParameterObject EcoWeatherFlow ecoWeatherFlow) {
        LambdaQueryWrapper<EcoWeatherFlow> wrapper = Wrappers.lambdaQuery();
        return R.ok(ecoWeatherFlowService.page(page, wrapper));
    }


    /**
     * 通过id查询天气流水表
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('exsecs_ecoWeatherFlow_view')" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(ecoWeatherFlowService.getById(id));
    }

    /**
     * 新增天气流水表
     * @param ecoWeatherFlow 天气流水表
     * @return R
     */
    @Operation(summary = "新增天气流水表" , description = "新增天气流水表" )
    @SysLog("新增天气流水表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('exsecs_ecoWeatherFlow_add')" )
    public R save(@RequestBody EcoWeatherFlow ecoWeatherFlow) {
        return R.ok(ecoWeatherFlowService.save(ecoWeatherFlow));
    }

    /**
     * 修改天气流水表
     * @param ecoWeatherFlow 天气流水表
     * @return R
     */
    @Operation(summary = "修改天气流水表" , description = "修改天气流水表" )
    @SysLog("修改天气流水表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('exsecs_ecoWeatherFlow_edit')" )
    public R updateById(@RequestBody EcoWeatherFlow ecoWeatherFlow) {
        return R.ok(ecoWeatherFlowService.updateById(ecoWeatherFlow));
    }

    /**
     * 通过id删除天气流水表
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除天气流水表" , description = "通过id删除天气流水表" )
    @SysLog("通过id删除天气流水表" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('exsecs_ecoWeatherFlow_del')" )
    public R removeById(@RequestBody Integer[] ids) {
        return R.ok(ecoWeatherFlowService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param ecoWeatherFlow 查询条件
   	 * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('exsecs_ecoWeatherFlow_export')" )
    public List<EcoWeatherFlow> export(EcoWeatherFlow ecoWeatherFlow,Integer[] ids) {
        return ecoWeatherFlowService.list(Wrappers.lambdaQuery(ecoWeatherFlow).in(ArrayUtil.isNotEmpty(ids), EcoWeatherFlow::getId, ids));
    }

	@Operation(summary = "最高气温曲线图" , description = "最高气温曲线" )
	@GetMapping("/maxWeaChart")
	public R maxWeaChart(String startDate,String endDate){
		return R.ok(ecoWeatherFlowService.getMaxChart(startDate,endDate),"最高气温曲线");
	}
}